<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePermissionsDetailsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        

        if (!Schema::hasTable('permissions_details')) { //如果不存在则建表
            Schema::create('permissions_details', function (Blueprint $table) {
                $this->create_table($table);
            });
        } else { //否则增量添加字段
            Schema::table('permissions_details', function (Blueprint $table) {
                $this->create_table($table);
            });
        }
        DB::statement("alter table `permissions_details` comment'权限分类->详情表'");

    }
    public function create_table($table)
    {
        $table->engine = 'InnoDB';
       
        if (!Schema::hasColumn('permissions_details', 'id')) {
            $table->increments('id');
        }
        if (!Schema::hasColumn('permissions_details', 'permission_id')) {
            $table->integer('permission_id')->default(0)->comment('权限id');
        }

        if (!Schema::hasColumn('permissions_details', 'explain')) {
            $table->string('explain', 32)->default('')->comment('权限说明');
        }

        if (!Schema::hasColumn('permissions_details', 'rank')) {
            $table->tinyInteger('rank')->default(0)->comment('排序');
        }

        if (!Schema::hasColumn('permissions_details', 'created_at')) {
            $table->timestamps();
        }
        if (!Schema::hasColumn('permissions_details', 'deleted_at')) {
            $table->softDeletes();
        }

    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // Schema::dropIfExists('permissions_details');
    }
}
